package com.lx.controller;/**
 * @ProjectName: lx
 * @Package: com.lx.controller
 * @ClassName: IndexController
 * @Author: 张晟睿
 * @Date: 2021/9/14 19:45
 * @Version: 1.0
 */

import com.alibaba.fastjson.JSON;
import com.lx.entity.LxEnv;
import com.lx.entity.LxEqu;
import com.lx.entity.LxPar;
import com.lx.entity.LxUser;
import com.lx.service.impl.LxEnvServiceImpl;
import com.lx.service.impl.LxEquServiceImpl;
import com.lx.service.impl.LxParServiceImpl;
import com.lx.service.impl.LxUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.json.Json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *@ClassName IndexController
 *@Description
 *@Author 张晟睿
 *@Date 2021/9/14
 **/
@RestController
@RequestMapping("/lx-index")
public class IndexController {
    @Autowired
    private LxEnvServiceImpl lxEnvService;
    @Autowired
    private LxEquServiceImpl lxEquService;
    @Autowired
    private LxParServiceImpl lxParService;
    @Autowired
    private LxUserServiceImpl lxUserService;
    @GetMapping("/index")
    @CrossOrigin
    public String getIndexMessage(){
        List<LxEnv> lxEnvs = lxEnvService.list();
        List<LxEqu> lxEqus = lxEquService.list();
        List<LxPar> lxPars = lxParService.list();
        List<LxUser> lxUsers = lxUserService.list();
        Map<String,Integer> countMap = new HashMap<>();

        countMap.put("env",lxEnvs.size());
        countMap.put("equ",lxEqus.size());
        countMap.put("par",lxPars.size());
        countMap.put("user",lxUsers.size());
        Map<String,Object> resultData = new HashMap<>();
        resultData.put("code",0);
        resultData.put("msg",null);
        resultData.put("data",countMap);
        return JSON.toJSONString(resultData);
    }
}
